package ngames.com.sushitv.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import ngames.com.sushitv.R;

/**
 * Created by Fearless on 2016/6/26.
 */
public class SearchHistoryAdapter extends RecyclerView.Adapter<SearchHistoryAdapter.historyHolder> {
    private List<String> historyStr;
    private LayoutInflater minflater;
    private Context context;
    public SearchHistoryAdapter(Context context, List<String> historyStr){
        this.historyStr=historyStr;
        this.context=context;
        minflater=LayoutInflater.from(context);

    }
    @Override
    public historyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View convertView = minflater.inflate(R.layout.view_textview_history, null);
        historyHolder viewHolder=new historyHolder(convertView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(historyHolder holder, int position) {
        for(int i=0;i<position;++i) {
            holder.historyText.setText(historyStr.get(i));
            if(i%2==0){
                holder.historyLinear.setBackgroundResource(R.color.searchFragment_history_item);
            }else{
                holder.historyLinear.setBackgroundResource(R.color.accountFragment_item);
            }

        }
    }

    @Override
    public int getItemCount() {
        return historyStr.size();
    }
    class historyHolder extends RecyclerView.ViewHolder{
        private TextView historyText;
        private LinearLayout historyLinear;
        public historyHolder(View itemView) {
            super(itemView);
            historyText= (TextView) itemView.findViewById(R.id.text_search_history);
            historyLinear= (LinearLayout) itemView.findViewById(R.id.linear_search_history);
        }
    }
}
